from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains


driver=webdriver.Edge()
driver.maximize_window()
driver.get('https://www.baidu.com/')
sleep(5)

dw=driver.find_element(By.ID,'kw')

#鼠标事件

#点击 双击 三击
ActionChains(driver).click(dw).perform()
ActionChains(driver).double_click(dw).perform()
ActionChains(driver).double_click(dw).click(dw).perform()

ActionChains(driver).move_to_element(dw).perform() #鼠标悬停
ActionChains(driver).drag_and_drop_by_offset(dw,300,50).perform() #鼠标拖拽
ActionChains(driver).click_and_hold(dw).perform() #鼠标长按
ActionChains(driver).release(dw).perform() #鼠标释放
ActionChains(driver).context_click(dw).perform() #鼠标右击

#键盘事件
#键盘回车
dw.send_keys(Keys.ENTER)

#键盘Tab 制表键
dw.send_keys(Keys.TAB)

#键盘Ctrl事件
dw.send_keys(Keys.CONTROL,'a')
dw.send_keys(Keys.CONTROL,'c')
dw.send_keys(Keys.CONTROL,'v')
dw.send_keys(Keys.CONTROL,'x')

#键盘shift事件
dw.send_keys(Keys.F1)
dw.send_keys(Keys.F2)
dw.send_keys(Keys.F3)
dw.send_keys(Keys.F4)
dw.send_keys(Keys.F5)
dw.send_keys(Keys.F6)
dw.send_keys(Keys.F7)
dw.send_keys(Keys.F8)
dw.send_keys(Keys.F9)
dw.send_keys(Keys.F10)
dw.send_keys(Keys.F11)
dw.send_keys(Keys.F12)

#键盘 方向 事件
dw.send_keys(Keys.LEFT)
dw.send_keys(Keys.UP)
dw.send_keys(Keys.RIGHT)
dw.send_keys(Keys.DOWN)

#键盘 删除 事件
dw.send_keys(Keys.DELETE)
dw.send_keys(Keys.BACKSPACE)
dw.send_keys(Keys.BACK_SPACE)

#键盘 空格 事件
dw.send_keys(Keys.SPACE)

#浏览器事件
driver.refresh() #刷新
driver.maximize_window() #窗口最大化
driver.minimize_window() #窗口最小化
driver.set_window_size(800,800) #窗口大小
driver.forward() # 前进
driver.back() # 后退

# 打印
print(driver.current_url)
print(driver.title)
print(dw.location)
print(dw.size)
print(dw.is_enabled())
print(dw.is_selected())
print(dw.is_displayed())
print(dw.get_dom_attribute('class'))